package com.yulan.bankback.controller.admin;


import cn.hutool.core.date.DateUtil;
import com.yulan.bankback.aop.Authorization;
import com.yulan.bankback.entity.result.RetResponse;
import com.yulan.bankback.entity.result.RetResult;
import com.yulan.bankback.log.Logger;
import com.yulan.bankback.service.admin.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bank_admin")
public class BankAdminController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private BlackUserService blackUserService;

    @Autowired
    private IllegalService illegalService;

    @Autowired
    private AbnormalService abnormalService;

    @Autowired
    private WebAttackService webAttackService;

    @Autowired
    private SystemService systemService;


    @Authorization({"admin"})
    @GetMapping("/violation_user/info/{interval}")
    public RetResult getViolationUserVo(@PathVariable(value = "interval") String interval) {
        return RetResponse.makeOKRsp(adminService.getViolationUserVo(interval));
    }

    @Authorization({"admin"})
    @PostMapping("/violation_user/info/")
    public RetResult getViolationUsers(String start, String end, String type,
                                       String username, String uid){
        return RetResponse.makeOKRsp(adminService.getByConditions(start, end, type, username, uid));
    }

    @Authorization({"admin"})
    @GetMapping("/kine_user_info/{interval}")
    public RetResult getKindUserVo(@PathVariable("interval") String interval){
        return RetResponse.makeOKRsp(blackUserService.getBlackUserVo(interval));
    }

    @Authorization({"admin"})
    @GetMapping("/black_user/all")
    public RetResult getAllBlackUser(){
        return RetResponse.makeOKRsp(blackUserService.getBlackUser());
    }

    @Authorization({"admin"})
    @GetMapping("/white_user/all")
    public RetResult getAllWhiteUser(){
        return RetResponse.makeOKRsp(blackUserService.getWhiteUser());
    }

    @Authorization({"admin"})
    @PostMapping("/white_user/search")
    public RetResult getWhiteUserByConditions(String start, String end, String type,
                                              String uid, String username){
        return RetResponse.makeOKRsp(blackUserService.getWhiteUserByConditions(start, end, type,
                username, uid));
    }


    @Authorization({"admin"})
    @PostMapping("/black_user/search")
    public RetResult getBlackUserByConditions(String start, String end, String type,
                                              String uid, String username){
        return RetResponse.makeOKRsp(blackUserService.getBlackUserByConditions(start, end, type,
                username, uid));
    }

    @Authorization({"admin"})
    @PostMapping("/black_user/add")
    public RetResult addBlackUser(String uid, String username, String type){
        String res = blackUserService.addBlackUser(uid, username, type);
        return StringUtils.equals(res, "success") ?
                RetResponse.makeOKRspMsg("添加成功") :
                RetResponse.makeErrRsp(res);
    }

    @Authorization({"admin"})
    @PostMapping("/white_user/add")
    public RetResult addWhiteUser(String uid, String username, String type){
        String res = blackUserService.addWhiteUser(uid, username, type);
        return StringUtils.equals(res, "success") ?
                RetResponse.makeOKRspMsg("添加成功") :
                RetResponse.makeErrRsp(res);
    }

    @Authorization({"admin"})
    @PostMapping("/black_user/remove")
    public RetResult removeBlackUser(String uid, String username){
        String res = blackUserService.removeBlackUser(uid, username);
        return res.equals("success") ?
                RetResponse.makeOKRspMsg("移除成功") :
                RetResponse.makeErrRsp(res);
    }

    @Authorization({"admin"})
    @PostMapping("/white_user/remove")
    public RetResult removeWhiteUser(String uid, String username){
        String res = blackUserService.removeWhiteUser(uid, username);
        return res.equals("success") ?
                RetResponse.makeOKRspMsg("移除成功") :
                RetResponse.makeErrRsp(res);
    }

    @Authorization({"admin"})
    @GetMapping("/illegal_trading/all")
    public RetResult getAllIllegalTrading(){
        return RetResponse.makeOKRsp(illegalService.getAllIllegalTrading());
    }

    @GetMapping("/user_account_safe/info/{interval}")
    public RetResult getUserAccountSafe(@PathVariable("interval") String interval){
        return RetResponse.makeOKRsp(illegalService.getAccountSafeVo(interval));
    }

    @Authorization({"admin"})
    @PostMapping("/illegal_trading/search")
    public RetResult getIllegalTradingConditions(String start, String end, String type,
                                                 String uid, String username){
        return RetResponse.makeOKRsp(illegalService.getIllegalTradingByConditions(start, end, type,
                username, uid));
    }

    @Authorization({"admin"})
    @GetMapping("/abnormal/info/{interval}")
    public RetResult getAbnormalInfo(@PathVariable("interval") String interval){
        return RetResponse.makeOKRsp(abnormalService.getAbnormalUserVo(interval));
    }

    @Authorization({"admin"})
    @GetMapping("/abnormal/all")
    public RetResult getAllAbnormal(){
        return RetResponse.makeOKRsp(abnormalService.getAllAbnormalUser());
    }


    @Authorization({"admin"})
    @PostMapping("/abnormal/search")
    public RetResult getAbnormalConditions(String start, String end, String type,
                                           String uid, String username, String ip){
        return RetResponse.makeOKRsp(
                abnormalService.getAbnormalUserConditions(start, end, type, username, uid, ip)
        );
    }


    @Authorization({"admin"})
    @PostMapping("/attack_event/search")
    public RetResult getAttackEventConditions(String start, String end, String type,
                                              String level, String ip){
        return RetResponse.makeOKRsp(
                webAttackService.getAttackEventConditions(start,end,type,level,ip)
        );
    }

    @Authorization({"admin"})
    @GetMapping("/attack_event/all")
    public RetResult getAllAttackEvent(){
        return RetResponse.makeOKRsp(webAttackService.getAllAttackEvent());
    }

    @Authorization({"admin"})
    @PostMapping("/black_ip_list/search")
    public RetResult getBlackIpConditions(String start, String end, String type,
                                          String country, String city, String ip){
        return RetResponse.makeOKRsp(
                webAttackService.getIpBlackListConditions(start,end,type,country, city, ip)
        );
    }

    @Authorization({"admin"})
    @GetMapping("/black_ip_list/all")
    public RetResult getAllBlackIp(){
        return RetResponse.makeOKRsp(webAttackService.getAllIpBlackList());
    }


    @Authorization({"admin"})
    @GetMapping("/system_safe/info")
    public RetResult getSystemSafeVo(){
        return RetResponse.makeOKRsp(systemService.getSystemSafeVo());
    }


    @Authorization({"admin"})
    @GetMapping("/user_experience/info/{interval}")
    public RetResult getUserExperienceVo(@PathVariable("interval") String interval){
        return RetResponse.makeOKRsp(systemService.getSystemExperienceVo(interval));
    }

    @Authorization({"admin"})
    @GetMapping("/user_safe/info")
    public RetResult getUserSafeVo(){
        return RetResponse.makeOKRsp(systemService.getUserSafeVo());
    }

}
